<?php

declare(strict_types=1);

namespace App\Request\Goods;

use App\Request\FormRequest;

class Good extends FormRequest
{
    /**
     * 场景
     * @var array|\string[][]
     */
    protected array $scenes = [
        'save' => [
            'products',
            'products.*.item_id',
            'products.*.title',
            'products.*.item_code',
            'products.*.price',
//            'products.*.item_url',
            // 'products.*.image_url',
//            'products.*.create_time',
        ],
        'status' => [
            'product_ids',
            'product_ids.*',
            'status'
        ],
        'destroy' => [
            'product_ids',
            'product_ids.*'
        ],
        'read' => [
            'product_id'
        ]
    ];

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'products' => 'required|array|max:50',
            'products.*.item_id' => 'required|max:60',
            'products.*.title' => 'required|max:100',
            'products.*.item_code' => 'required|max:60',
            'products.*.price' => 'required|numeric|min:0',
//            'products.*.item_url' => 'required|url',
            'products.*.image_url' => 'required|url',
//            'products.*.create_time' => 'required|digits:13',

            'products.*.product_id' => 'required|string|max:40',
            'products.*.no' => 'alpha_dash|max:40',
            'products.*.barcode' => 'string|max:40',
            'products.*.name' => 'required|max:50',
            'products.*.brand' => 'max:30',
            'products.*.content' => 'nullable',
            'products.*.image' => 'required|url',
            'products.*.images' => 'array',
            'products.*.images.*' => 'required|url',
            'products.*.video' => 'url',
            'products.*.enable_at' => date('Y-m-d H:i:s'),
            'product_ids' => 'required|array',
            'product_ids.*' => 'required|string|max:40',
            'status' => 'required|boolean',
            'product_id' => 'required|string|max:40'
//            'skus' => 'nullable|array',
//            'skus.*.sku_id' => 'required|alpha_dash|max:40',
//            'skus.*.sku_code' => 'alpha_dash|max:40',
//            'skus.*.price' => 'required|numeric|min:0',
//            'skus.*.image' => 'required|url',
//            'skus.*.barcode' => 'string|max:40',
//            'skus.*.attr' => 'required|max:255'
        ];
    }
}
